@extends('admin.layout.layout')
@section('content') 
<div class="row"> 
    <div class="col-lg-12">
        <h1 class="page-header">分类添加</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>  
<div class="panel-body">
    <div class="dataTable_wrapper">
        <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
        <div class="row">
        <div class="col-sm-6">
        <div class="dataTables_length" id="dataTables-example_length">
        <label>
            查看<select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                    <option value="10">5</option>
                    <option value="25">8</option>
                    <option value="50">10</option>
                    <option value="100">15</option>
                </select>行
        </label>
        </div>
        </div>

        <div class="col-sm-6">
        <div id="dataTables-example_filter" class="dataTables_filter">
        <label>
            列表名:<input class="form-control input-sm" name="lk" aria-controls="dataTables-example" type="search">
        </label>
        <button class="btn btn-primary" type="button">查询</button>
        </div>
        </div>
        </div>

        <div class="row">
        <div class="col-sm-12">
        <table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
            <thead>
                <tr role="row"><th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 175px;" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending">ID</th>
                <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 203px;" aria-label="Browser: activate to sort column ascending">类名</th>
                <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 184px;" aria-label="Platform(s): activate to sort column ascending">路径</th>
                <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 150px;" aria-label="Engine version: activate to sort column ascending">状态</th>
                <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 108px;" aria-label="CSS grade: activate to sort column ascending">操作</th></tr>
            </thead>
        <tbody>  
        @foreach($cates as $k=>$v)
            <tr class="gradeA odd" role="row">
                <td class="sorting_1 sid">{{$v->id}}</td>
                <td>{{$v->name}}</td>
                <td>{{$v->path}}</td>
                <td class="center">{{str_replace([1,2],['启用','未启用'],$v->status)}}</td>
                <td class="center">
                    <a class = "fa fa-trash-o delete">删除</a>
                    &nbsp;|&nbsp;
                    <a href = "{{url('/admin/cate/edit',['id'=>$v->id])}}" class = "fa fa-wrench ">修改</a>
                </td>
            </tr>
        @endforeach
            </tbody>
        </table>
        </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite"></div>
            </div>
        <div class="col-sm-6">
        <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
            <ul class="pagination">
                <li class="paginate_button previous disabled" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
                    <a href="#">上一页</a>
                </li>
                <li class="paginate_button active" aria-controls="dataTables-example" tabindex="0">
                    <a href="#">1</a>
                </li>
                <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                    <a href="#">2</a>
                </li>
                <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                    <a href="#">3</a>
                </li>
                <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                    <a href="#">4</a>
                </li>
                <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                    <a href="#">5</a>
                </li>
                <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                    <a href="#">6</a>
                </li>
                <li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">
                    <a href="#">下一页</a>
                </li>
            </ul>
        </div>
        </div>
        </div>
        </div>
    </div>
</div>
@endsection
@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
    $('.delete').click(function()
    {
        var id = $(this).parents('tr').find('.sid').html();
        var dd = $(this);
        // 发送ajax
        $.post('/admin/cate/delete',{id:id},function(data)
        {
            if(data == 1)
            {
                alert('当前分类下有子分类不允许删除');
            }else{
                dd.parents('tr').remove();
                alert('删除成功');
            }
        })
        return false;
    })
</script>
@endsection